var express = require('express');
var router = express.Router();
var {pimodel
} = require('../model/model');

// 添加个人信息
router.post('/addpi',async(req,res)=>{
    let obj=req.body;
    await pimodel.create(obj);
    res.send({
      code:200,
      msg:'添加成功'
    })
  })
  // 个人信息列表
  router.get('/pi',async(req,res)=>{
    let pilist=await pimodel.find();
    res.send({
      code:200,
      pilist
    })
  })
  // 修改
  router.post('/updatepi', async (req, res) => {
    let body = req.body;
    console.log('Received update request:', body); // 添加日志输出
    let _id = body._id;
    try {
      await pimodel.updateOne({ _id }, body);
      res.send({
        code: 200,
        msg: '修改成功'
      });
    } catch (error) {
      console.error('Error updating database:', error);
      res.send({
        code: 500,
        msg: '修改失败'
      });
    }
  });
module.exports = router;
